﻿<%@ Page Title="BOM" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
   CodeBehind="BOM.aspx.cs" Inherits="Billder.BOM" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:HiddenField ID="txtAction" Value="none" runat="server"/>
<asp:HiddenField ID="txtPKBOM" Value="none" runat="server"/>
<iframe id="imgIfr" src="" width="0" height="0" style="border:none;"></iframe>
<table width="100%">
    <tr>
        <td>
            <label for="txtAssembly">Nombre:</label><br/>
            <asp:TextBox runat="server" ID="txtAssembly" CssClass="textEntry" onchange="updateBOMData();"></asp:TextBox><br/>
            <label for="txtRevision">Revision:</label><br/>
            <asp:TextBox runat="server" ID="txtRevision" CssClass="textEntry" OnChange="updateBOMData();"></asp:TextBox><br/>
            <label for="txtDescription">Descripcion:</label><br/>
            <asp:TextBox runat="server" ID="txtDescription" CssClass="textEntry" OnChange="updateBOMData();"></asp:TextBox><br/>
            <label for="txtSalesQty">Volumen de venta(mensual):</label><br/>
            <asp:TextBox runat="server" ID="txtSalesQty" CssClass="textEntry" OnChange="updateBOMData();"></asp:TextBox><br/>
            <img alt="Part photo" id="partImg" src="Image.aspx?PK=0&img=none" height="172" ondblclick="activateImg();"/><br /><input type="file" name="partImageFile" id="partImageFile" onchange="fnUploadImg();" /><BR/>
            <label for="txtPartNumber">Agregar numero de parte:</label><br/>
            <asp:TextBox runat="server" ID="txtPartNumber" CssClass="textEntry"></asp:TextBox><asp:HiddenField runat="server" ID="txtFKPartNumber"></asp:HiddenField><asp:HiddenField runat="server" ID="txtItem"></asp:HiddenField> x    
            <asp:TextBox runat="server" ID="txtQty" CssClass="textEntrySmall"></asp:TextBox><asp:ImageButton ImageUrl="Images/add.png" runat="server" OnClientClick="addPart(); return false;" /><br/>
            <label for="txtLOH">LOH:</label><br/>
            <asp:TextBox runat="server" ID="txtLOH" CssClass="textEntry" OnChange="updateBOMData();"></asp:TextBox><br/>
            <label for="txtProfit">Profit:</label><br/>
            <asp:TextBox runat="server" ID="txtProfit" CssClass="textEntry" OnChange="updateBOMData();"></asp:TextBox><br/>
            <table>
                <tr>
                    <td>
                        <asp:Button runat="server" id="btnOpen" Text="Abrir" CssClass="submitButton" OnClientClick="showOpenList(); return false" />
                    </td>
                    <td>
                        <asp:Button runat="server" id="btnSave" Text="Guardar"  CssClass="submitButton"/>
                    </td>
                    <td>
                        <asp:Button runat="server" id="btnApprove" Text="Aprobar"  
                            CssClass="submitButton" onclick="btnApprove_Click"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Button runat="server" id="btnPrint" Text="Imprimir"  CssClass="submitButton"/>
                    </td>
                    <td>
                        <asp:Button runat="server" id="btnSaveAs" Text="Guardar como" CssClass="submitButton" />
                    </td>
                </tr>
            </table>
        </td>
        <td width="70%"><div id="BOMDiv">&nbsp;</div></td>
    </tr>
</table>
<div id="divList" style="display: none;" runat="server">&nbsp;</div>
<asp:HiddenField ID="txtImgCode" runat="server"></asp:HiddenField>
<asp:HiddenField ID="txtFKAssembly" runat="server"></asp:HiddenField>
<textarea rows="20" cols="50" id="txtBOM" name="txtBOM"></textarea>

<script type="text/javascript" src="Scripts/Common.js"></script>
    <script type="text/javascript" src="Scripts/BOM.js"></script>
<script type="text/javascript">

    prepareEdit = function (pk) {
        document.getElementById("MainContent_txtPKBOM").value = pk;
        document.getElementById("MainContent_txtAction").value = "prepareEdit";
        document.getElementById("MainContent_txtAction").form.submit();
    }

   
    $("#MainContent_divList").dialog({ autoOpen: false, modal: true });
    showOpenList = function () {
        $("#MainContent_divList").load("BOMList.aspx?q=none", { method: "GET" });
        $("#MainContent_divList").dialog("open");
    }
    customSelect = function (event, item) {

        if (item.length == 1) {
            $("#MainContent_txtPartNumber").val("");
            return false;
        }
    }
    PNResult = function (event, item) {

        if (item[1] == " ") {
            window.open(item[3]);
            setTimeout('$("#badgeDiv").load("Badge.aspx");', 1000);
        }
        fnHdlJQResult("MainContent_txtFKPartNumber", item);
        $("#MainContent_txtItem").val(item[3]);
    }
    PNSearch = function (event, ui) {
        fnHdlJQSearch("MainContent_txtFKPartNumber");
    }
    PNParse = function   (data , ui){fnHdlJQParse("MainContent_txtFKPartNumber", data);
    }
    $("#MainContent_txtPartNumber").autocomplete("Part.aspx", { autocomplete:true, select:customSelect, parse: PNParse, formatResult: function (item) { return item[2]} }).result(PNResult).search(PNSearch);
    showAction = function () {
        var action = $("#MainContent_txtAction").val();
        var shownAction = action;
        if (action == "new" || action == "none") {
            shownAction = "Creando un nuevo ensamble"
        }
        if (action == "commitEdit") {
            shownAction = "Editando un ensamble"
        }
        $.pnotify({
            pnotify_title: 'Actualmente usted esta:',
            pnotify_text: shownAction,
            pnotify_hide: false
        });
    }
    addPart = function () {
        var newPart;
        if ($("#MainContent_txtItem").val() == "PartMaster") {
            newPart = new Part($("#MainContent_txtFKPartNumber").val(), $("#MainContent_txtPartNumber").val(), $("#MainContent_txtQty").val());
        } else {
            newPart = new BOM($("#MainContent_txtFKPartNumber").val(), $("#MainContent_txtPartNumber").val(), 1, { Qty: $("#MainContent_txtQty").val() });
        }
        currentAssy.add(newPart);
        updateBOMData();
        $("#MainContent_txtPartNumber").val("");
        $("#MainContent_txtQty").val("");
    }

    updateBOMData = function(){
        currentAssy.Name = $("#MainContent_txtAssembly").val();
        currentAssy.Rev = $("#MainContent_txtRevision").val();
        currentAssy.Desc = $("#MainContent_txtDescription").val();
        currentAssy.LOH = $("#MainContent_txtLOH").val();
        currentAssy.Profit = $("#MainContent_txtProfit").val();
        currentAssy.SalesQty = $("#MainContent_txtSalesQty").val();
        $("#BOMDiv").html(currentAssy.asHTML());
        $("#txtBOM").text(currentAssy.asXML());
    }
    toggle = function (who) {
        currentClass = who.getAttribute("class");
        if (currentClass.indexOf("expanded") != -1) {
            who.setAttribute("class", "subAssy");
        } else {
            who.setAttribute("class", "subAssy expanded");
        }
    }
    showAction();
    var currentAssy = new BOM(0, $("#MainContent_txtAssembly").val(), $("#MainContent_txtRevision").val());
    </script> 
    <div id="later" runat="server"></div>
</asp:Content>
